package com.ivt.dao;

import java.util.List;

import javax.persistence.QueryHint;

import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.jpa.repository.QueryHints;

import com.ivt.model.Teacher;

public interface TeacherDao extends JpaRepository<Teacher, Long> {

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query(value = "SELECT  count(s) FROM  Teacher s where s.account = ?1")
	long existsByAccount(String account);

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query("SELECT  count(s) FROM  Teacher s where s.account = ?1 and s.id <> ?2")
	long existsByAccountAndId(String account, Long studentId);

	@QueryHints({ @QueryHint(name = org.hibernate.annotations.QueryHints.CACHEABLE, value = "true") })
	@Query(value = "SELECT  s FROM  Teacher s where s.account = ?1")
	List<Teacher> findByAccount(String account);
}
